package com.ruoyi.task;

import com.ruoyi.service.UserHealthDataService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class UserHealthDataTask {
    private final UserHealthDataService healthDataService;

    public UserHealthDataTask(UserHealthDataService healthDataService) {
        this.healthDataService = healthDataService;
    }

    @Scheduled(cron = "0 0 * * * ?")
    public void fetchHealthData() {
        System.out.println("定时任务触发时间: " + LocalDateTime.now());
        for (int type = 0; type <= 4; type++) {
//            System.out.println("处理数据类型: " + type);
            healthDataService.fetchAndSaveData(type);
        }
    }
}
